﻿using System;
using UnityEngine;

namespace SillyCube
{
    public class ChildTrigger : MonoBehaviour
    {
        private CubeController cubeController;
        
        private void Start()
        {
            cubeController = FindValidFatherController(transform);
        }

        private static CubeController FindValidFatherController(Transform child)
        {
            var parent = child.parent;

            if (parent is null)
                return null;

            var cubeController = parent.GetComponent<CubeController>();
            if (cubeController is null)
            {
                return FindValidFatherController(parent);
            }

            return cubeController;
        }

        private void OnTriggerEnter(Collider other)
        {
            Debug.Log("trigger enter");
        }
    }
}